﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace FanaticRock.Theme.Converters
{
    ///<summary>和StringFormat实现的不一样！因为我们希望显示 2:10:1-> 130:1 </summary>
    public class TimeSpanToMMSSFormatConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value is TimeSpan timeSpan)
            {
                var m = timeSpan.Hours * 60 + timeSpan.Minutes;
                var s = timeSpan.Seconds;
                return $"{m:00}:{s:00}";
            }

            throw new ArgumentNullException($"{value}");
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #region singleton

        private static Lazy<TimeSpanToMMSSFormatConverter> _instance = new Lazy<TimeSpanToMMSSFormatConverter>();
        public static TimeSpanToMMSSFormatConverter Instance => _instance.Value;

        #endregion
    }
}
